<template>
	<view class="u-tabs"> 
		<!-- <scroll-view scroll-x class="calss-list" v-if="tabs.length&&tabs.length >4">
				<view class="u-icon-box " v-for="(item, index) in tabs" :key="index" :class="{'selectedTab': selTab==index}"
				@tap="swichTabs(index, item.id)">
				<image :src="ossUrl + item.categoryIcon"></image>
				<tui-text :text="item.categoryName" size="30" fontWeight="600"></tui-text>
				</view>
          </scroll-view>
          <view class="calss-list flexcontent" v-else>
					<view class="u-icon-box  " v-for="(item, index) in tabs" :key="index" :class="{'selectedTab': selTab==index}"
					@tap="swichTabs(index, item.id)">
					<image :src="ossUrl + item.categoryIcon"></image>
					<tui-text :text="item.categoryName" size="30" fontWeight="600"></tui-text>
				</view>
          </view>--> 
		<view>
          <scroll-view scroll-x class="calss-list" v-if="tabs.length&&tabs.length >4">
            <view @tap="swichTabs(index, calss.id)" :class="selTab===index ? 'coach-item activeItem':'coach-item'" v-for="(calss, index) in tabs" :key="index"> 
              <image class="image" :src="ossUrl+calss.categoryIcon" mode="aspectFill"></image>
			  <text class="name">{{calss.categoryName}}</text> 
            </view>
          </scroll-view>
          <view class="calss-list flexcontent" v-else>
            <view   @tap="swichTabs(index, calss.id)" :class="selTab===index ? 'coach-item activeItem':'coach-item'" v-for="(calss, index) in tabs" :key="index"> 
              <image class="image" :src="ossUrl+calss.categoryIcon" mode="aspectFill"></image>
			  <text class="name">{{calss.categoryName}}</text> 
            </view>
          </view>
        </view>
	</view>
</template>

<script>
	export default {
		name: 'tutorStoreShort',
		emits: ['change'],
		props: {
			// 分类数据列表
			tabs: {
				type: Array,
				default: []
			},
			//oss
			ossUrl:{
				type: String,
				default:''
			}
		},
		data() {
			return {
				selTab: 0,
				selCategoryId:''
			};
		},
		methods: {
			// 点击标题切换当前页时改变样式
			swichTabs: function(index, id) {
				if (this.currentTab == index) {
					return false;
				} else {
					this.selTab = index;
					this.selCategoryId = id;
					this.$emit('change', {
						index: Number(index),
						categoryId: id
					});
				}
			}
		}
	};
</script>

<style scoped>
	.u-tabs {
		width: 100%; 
		background-color: #f5f5f5
	}

 
	.calss-list { 
      white-space: nowrap;
      padding: 30rpx 10rpx;
      background-color: #fff; 
	 
	}
	.flexcontent{
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.coach-item {
      display: inline-block; 
      width: 156rpx;
      height: 156rpx; 
      text-align: center;
      background-color: #EEEEEE; 
	  margin-right: 10rpx;
      border-radius: 24rpx 24rpx 24rpx 24rpx;
		 
	  }
	  .image {
		  width: 80rpx;
		  height: 80rpx;
		  border-radius: 50%;
		  margin-bottom:4rpx;
		  margin-top: 20rpx;
		}
		
		.name {
		  display: block;
		  font-size: 24rpx;
		  color: #333;
		}
		
		.tag {
		  display: block;
		  font-size: 18rpx;
		  color: #999;
		}
    .activeItem{  
      position: relative; /* 添加这一行 */
      background-image: url('/static//home/bg_hover.png');
      background-position: 100%;
      background-repeat: no-repeat;
      background-size: cover;
    } 
 
	.selectedTab {
		height: 171rpx !important;
		background: transparent url("");
		background-size: 100% 100%;
	}
</style>